package com.five.mobile.controller;

import com.five.core.result.Result;
import com.five.pojo.vo.CategoryTreeVo;
import com.five.service.CategoryRpcService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @DubboReference
    private CategoryRpcService categoryRpcService;
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result list(){
        System.err.println("查询分类树");
        // 添加空值检查
        if (categoryRpcService == null) {
            System.err.println("=== categoryRpcService 为 null ===");
            return Result.buildFail("服务未初始化");
        }
        List<CategoryTreeVo> categoryTreeVos = categoryRpcService.queryCategoryTree();
        return Result.buildSuccess(categoryTreeVos);
    }
}
